<template>
  <view>
    <view class="search-box">
    <my-search-bar placeholder='搜索一下' bgColor='#c00000'></my-search-bar>
    </view>
    <!-- 轮播图 -->
    <swiper autoplay interval='3000' circular>
      <swiper-item v-for="item in swiperList" :key='item.goods_id'>
        <image :src="item.image_src" alt="">
      </swiper-item>
    </swiper>
    <!-- 导航菜单 -->
    <view class="nav-list">
      <image
      class="nav-img"
      v-for="item in catitems"
      :key='item.name'
      :src="item.image_src"
        mode="scaleToFill"
        @click="goToNav(item.name)"
      />
    </view>
    <!-- 楼层渲染 -->
    <view>
      <view  v-for="item in floorList" :key='item.floor_title.name'>
        <!-- 楼层标题 -->
      <image
       class="floor-title"
        :src="item.floor_title.image_src"
        mode="scaleToFill"
      />
      <!-- 楼层内容 -->
       <view class="floor-img-box">
         <!-- 左边图片 -->
       <navigator :url="'/subpkg/goodList/index?'+item.product_list[0].navigator_url">
          <image
          :style="{width:item.product_list[0].image_width+'rpx'}"
          :src="item.product_list[0].image_src"
          mode="widthFix"
         />
       </navigator>
         <!-- 右边图片 -->
         <view class="right-img-box">
         <navigator :url="'/subpkg/goodList/index?'+items.navigator_url" v-for="(items,index) in item.product_list"
            :key="items.name">
         <image
             v-show="index>0"
            :style="{width:items.image_width+'rpx'}"
            :src="items.image_src"
             mode="widthFix"
          />
         </navigator>
         </view>
       </view>
    </view>
    </view>
  </view>
</template>
<script>
export default {
  data() {
    return {
      swiperList: [], //轮播图数据
      catitems: [], // nav列表数据
      floorList: [],
    };
  },
  onLoad() {
    this.getSwiperData();
    this.getNavData();
    this.getFloorData();
  },
  methods: {
    async getSwiperData() {
      const res = await uni.$request({
        url: "home/swiperdata",
      });
      if (res.meta.status === 200) {
        this.swiperList = res.message;
      }
    },
    async getNavData() {
      const res = await uni.$request({
        url: "home/catitems",
      });
      // console.log(res)
      if (res.meta.status === 200) {
        this.catitems = res.message;
      }
    },
    goToNav(name) {
      if (name === "分类") {
        uni.switchTab({ url: "/pages/category/index" });
      }
    },
    async getFloorData() {
      const res = await uni.$request({
        url: "home/floordata",
      });
      res.message.forEach(v => {
        v.product_list.forEach(vt=>{
         vt.navigator_url =vt.navigator_url.split('?')[1]
        })
      });
      // console.log(res)
      if (res.meta.status === 200) {
        this.floorList = res.message;
      }
    },
    
  },
};
</script>
<style lang="scss" scoped>
.search-box {
  // 设置定位效果为“吸顶”
  position: sticky;
  // 吸顶的“位置”
  top: 0;
  // 提高层级，防止被轮播图覆盖
  z-index: 999;
}

swiper {
  height: 400rpx;

  .swiper-item,
  image {
    width: 100%;
    height: 100%;
  }
}

.nav-list {
  display: flex;
  justify-content: space-around;
  margin: 15px 0;

  .nav-img {
    width: 128rpx;
    height: 140rpx;
  }
}

.floor-title {
  height: 60rpx;
  width: 100%;
  display: flex;
}

.right-img-box {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
}

.floor-img-box {
  display: flex;
  padding-left: 10rpx;
}
</style>
